package com.mm.controller;

import com.mm.domain.User;
import com.mm.repository.UserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.serviceregistry.Registration;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    private UserRepository userRepository;

    //用于登录测试,这里假设用户名是唯一的
    @GetMapping("/findByName")
    public User findByName(@RequestParam("username") String username){
        List<User> users =  userRepository.findByName(username);
        if(users.isEmpty()){
            return null;
        }
        return users.get(0);
    }
}
